<%-- Copyright (c) 2002 BroadVision, Inc. All rights reserved              --%>
<%-- The product described in this manual may be protected by one or more  --%>
<%-- U.S. and International patents. The BroadVision One-To-One software   --%>
<%-- is covered by U.S. patent 5,710,887.                                  --%>
<%--                                                                       --%>
<%-- TRADEMARKS: BroadVision and the BroadVision logo are registered       --%>
<%-- trademarks, and BroadVision One-To-One is a trademark of BroadVision, --%>
<%-- Inc. IONA and Orbix are trademarks of IONA Technologies, Ltd. RSA,    --%>
<%-- MD5, and RC2 are trademarks of RSA Data Security, Inc. All other      --%>
<%-- trademarks, service marks, and trade names belong to their respective --%>
<%-- owners. BroadVision, Inc. disclaims any proprietary interest in the   --%>
<%-- marks and names of others.                                            --%>
<%--                                                                       --%>

<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean"%>
<%@ taglib uri="/WEB-INF/struts-bean-el.tld" prefix="bean-el" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html"%>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic"%>
<%@ taglib uri="/WEB-INF/bv-html.tld" prefix="bvhtml"%>
<%@ taglib uri="/WEB-INF/c.tld" prefix="c" %>

<%@include file="/mt/common/pickerPopupHelper.jsp" %>

<%@ page import="java.util.List" %>
<%@ page import="com.broadvision.emarketing.criteriabuilder.ConditionTreeNode"%>
<%@ page import="com.broadvision.emarketing.criteriabuilder.Tree" %>
<%@ page import="com.broadvision.emarketing.action.Constants"%>

<SCRIPT>
function checkMaxLength(taText,len)
{
    if (taText.value.length > len)
        taText.blur();
}

function doAction(action, myform)
{   
    myform.action='<html:rewrite page="'+action+'" />';
    myform.submit();
    return true;
}

function doCancel(myform) {
    action = '/em/ruleset/rulesList.do?ruleSetOid=' + myform.ruleSetOid.value;
    myform.action='<html:rewrite page="'+action+'" />';
    myform.submit();
    return true;
}

function checkNumberOnly(e) {
    var charCode = (navigator.appName == "Netscape") ? e.which : e.keyCode;
    if (charCode > 31 && (charCode < 48 || charCode > 57)) {
      return false;
    }
    else {
      return true;
    }
}

function validateForm(myform) 
{   
    if( validate(myform) == false)
      return false;
    
    var val;
    for (i=0;i<myform.ruleActionType.length;i++)
    {
    	if (myform.ruleActionType[i].checked)
    	{
    	   val = myform.ruleActionType[i].value;
    	}
    }
     
    if( val == "1" && myform.itemKey.value == "") {
          alert(" <bean:message bundle="em" key="emarketing.ruleset.ruleSetEdit.javaScript.alert.selectItem" /> ");
          return false;
    }     
     
    if( val == "2" && myform.categoryPath.value == "") {
          alert(" <bean:message bundle="em" key="emarketing.ruleset.ruleSetEdit.javaScript.alert.selectCategory" /> ");
          return false;
    }     
    return true;
}

function onSelectContent( selectedOids, selectedNames) {
  theForm = document.emRuleDetailForm;
  theForm.itemKey.value = selectedNames.toString();
  theForm.contentOid.value = parseInt(selectedOids.toString());
}

function onSelectCategory( selectedOids, selectedNames) {
  theForm = document.emRuleDetailForm;
  theForm.categoryPath.value = selectedNames.toString();
  theForm.categoryOid.value = parseInt(selectedOids.toString());

}


function onClickItemAction( form ) {

  form.browseItem.disabled=false;

  form.browseCategory.disabled=true;

  form.categoryPath.value="";
  
  form.includeSubCategory.disabled=true;
  form.includeSubCategory.checked=false;
  
  form.numItems.disabled=true;
  form.numItems.value=1;

}

function onClickCategoryAction( form ) {

  form.itemKey.value="";
  
  form.browseItem.disabled=true;
  
  form.browseCategory.disabled=false;
  form.includeSubCategory.disabled=false;
  form.numItems.disabled=false;
  
}


</SCRIPT>

<html:javascript formName="emRuleDetailForm" method="validate" />

<c:set var="formBean" value="${emRuleDetailForm}" />
<c:set var="formBeanMap" value="${formBean.map}" />
<table width="100%" border="0" cellspacing="0" cellpadding="0"
	class="zoneFive">
	<tr>
		<td valign="top" width="100%">
		<div class="pageTitle">
		    <bean-el:message bundle="em" key="emarketing.ruleSet.rule.pageTitle.editRule" arg0="${formBeanMap.ruleName}"/>
		</div>
		<div class="errorMessage"><html:errors bundle="em"/></div>
		<div><%@include file="/mc/common/pagetab.jsp"%></div>
		<div class="pageInstructions">
			<bean:message bundle="em" key="emarketing.ruleSet.rule.pageInstruction" />
		</div>
		<div class="pageSubtitle">
			<bean:message bundle="em" key="emarketing.ruleSet.rule.header.ruleSummary" />
		</div>
		<html:form action="/em/ruleset/ruleSave" onsubmit="return validateForm(this);">
		<html:hidden name="emRuleDetailForm" property="ruleSetOid" />
		<html:hidden name="emRuleDetailForm" property="ruleOid" />
		<html:hidden name="emRuleDetailForm" property="actionType" />
			<table width="100%" border="0" cellspacing="0" cellpadding="0" class="labelForm">
				<tr>
					<td valign="top" wrap class="label" width="30%">
						<bean:message bundle="em" key="emarketing.ruleset.lable.rule.name" />*:
					</td>
					<td valign="top" wrap class="labelField" width="70%">
						<html:messages id="nameError" property="ruleName" bundle="em" />
						<c:if test="${not empty nameError}">
						              <span class="errorMessage">
						                <c:out value="${nameError}" />
						              </span>
						              <br>
            					</c:if>	
						<html:text name="emRuleDetailForm" property="ruleName" size="30" maxlength="80" />
					</td>
				</tr>
				<tr>
					<td valign="top" wrap class="label" width="30%">
						<bean:message bundle="em" key="emarketing.ruleset.lable.rule.description" />:
					</td>
					<td valign="top" wrap class="labelField" width="70%">
						<html:messages id="descriptionError" property="ruleDescription" bundle="em" />
						<c:if test="${not empty descriptionError}">
							<span class="errorMessage">
								<c:out value="${descriptionError}" />
							</span>
						<br>
            					</c:if>	
						<html:textarea name="emRuleDetailForm" property="ruleDescription" onkeypress="checkMaxLength(this,255)"
						rows="3" cols="40" />
					</td>
				</tr>
				<tr>
					<td valign="top" wrap class="label" width="30%">
						<bean:message bundle="em" key="emarketing.ruleSet.ruleSetSummary.lable.offerContentType" />:
					</td>
					<td valign="top" wrap class="labelField" width="70%">
						<bean:write name="emRuleDetailForm" property="contentTypeName" />
						<html:hidden name="emRuleDetailForm" property="contentType" />
					</td>
				</tr>
				<tr>
					<td valign="top" wrap class="label" width="30%">
						<bean:message bundle="em" key="emarketing.ruleset.ruleSetEdit.lable.evaluationMethod" />:
					</td>
					<td valign="top" wrap class="labelField" width="70%">
					<logic:equal name="emRuleDetailForm" property="evalMethod" value="ALL" >
						<bean:message bundle="em" key="emarketing.ruleset.ruleSetEdit.lable.evaluateall"/>
					</logic:equal>
					<logic:equal name="emRuleDetailForm" property="evalMethod" value="FIRST" >
						<bean:message bundle="em" key="emarketing.ruleset.ruleSetEdit.lable.evaluatefirst"/>
					</logic:equal>
					</td>
				</tr>
			</table>

			<div class="pageSubtitle">
				<span class="left">
					<bean:message bundle="em" key="emarketing.ruleSet.rule.lable.eventDateSelection" />
				</span>
				<span class="right">
				  <input type=hidden name=fromType value=ruleset>
  				<input type="button" name="modifyCriteria" class="inputButton" 	value="<bean:message bundle="em" key="emarketing.ruleset.button.modifyCriteria"/>" 
						onClick="doAction('/em/cb/ruleNewCriteria.do', this.form);" />
				</span>
			</div>
            <%
              Tree conditionTree = (Tree)session.getAttribute(Constants.CRITERIA_TREE);
              request.setAttribute("conditionList", conditionTree.getPreorderNodeList(false, false));
            %>
            <jsp:include page="/em/criteriabuilder/conditionListViewSection.jsp" />

			<div class="pageSubtitle">
				<bean:message bundle="em" key="emarketing.ruleSet.rule.header.ruleAction" />*
			</div>
                  <table width="100%" border="0" cellspacing="0" cellpadding="0" class="labelForm">
				<tr>
					<td class="labelField" width="30%">
					<html:radio name="emRuleDetailForm" property="ruleActionType" value="1" onclick="onClickItemAction(this.form)" />
					<bean:message bundle="em" key="emarketing.ruleset.ruleSetEdit.radio.value.pickOneItem" />
					</td>
					<td class="labelField" width="70%">
					<html:text name="emRuleDetailForm" size="30" property="itemKey" disabled="true"/>
					<logic:equal name="emRuleDetailForm" property="ruleActionType" value="1" >
						<input type="button" name="browseItem"
							value="<bean:message bundle="em" key="button.browseItem"/>"
							class="inputButton" onclick="doPickerPopupAction('<html:rewrite page="/mt/pickerPopup.do"/>', 'onSelectContent', this.form.contentType.value, null, null, null, true, false, true);" /> 
				        </logic:equal>
				        <logic:notEqual name="emRuleDetailForm" property="ruleActionType" value="1" >
						<input type="button" name="browseItem"
							value="<bean:message bundle="em" key="button.browseItem"/>"
							class="inputButton" onclick="doPickerPopupAction('<html:rewrite page="/mt/pickerPopup.do"/>', 'onSelectContent', this.form.contentType.value, null, null, null, true, false, true);" disabled="true" /> 
					</logic:notEqual>				        				        
					</td>
					<html:hidden name="emRuleDetailForm" property="contentOid"/>
				</tr>
				<tr>
					<td class="labelField" width="30%">
					<html:radio name="emRuleDetailForm" property="ruleActionType" value="2" onclick="onClickCategoryAction(this.form)" />
						<bean:message bundle="em" key="emarketing.ruleset.ruleSetEdit.radio.value.pickCategory" />
					</td>
					<td class="labelField" width="70%">
					<html:text name="emRuleDetailForm" size="30" property="categoryPath" disabled="true"/>
					<logic:equal name="emRuleDetailForm" property="ruleActionType" value="2" >
						<input type="button" name="browseCategory"
							value="<bean:message bundle="em" key="button.browseCategory"/>"
							class="inputButton" onclick="doPickerPopupAction('<html:rewrite page="/mt/categoryPickerPopup.do"/>', 'onSelectCategory', this.form.contentType.value, null, null, null, true, false, false );" />
					     	<html:hidden name="emRuleDetailForm" property="categoryOid"/>
					</logic:equal>
					<logic:notEqual name="emRuleDetailForm" property="ruleActionType" value="2" >
						<input type="button" name="browseCategory"
							value="<bean:message bundle="em" key="button.browseCategory"/>"
							class="inputButton" onclick="doPickerPopupAction('<html:rewrite page="/mt/categoryPickerPopup.do"/>', 'onSelectCategory', this.form.contentType.value, null, null, null, true, false, false );" disabled="true"/>
					     	<html:hidden name="emRuleDetailForm" property="categoryOid"/>
					</logic:notEqual>					
					</td>
				</tr>
				<tr>
					<td class="labelField" width="30%">
					</td>
					<td class="labelField" width="70%">
						<html:messages id="numItemsError" property="numItems" bundle="em" />
						<c:if test="${not empty numItemsError}">
							<span class="errorMessage">
							   <c:out value="${numItemsError}" />
							</span>
            					</c:if>	
            				<bean:message bundle="em" key="emarketing.ruleset.text.numContents" />*:
            				<logic:equal name="emRuleDetailForm" property="ruleActionType" value="2" >
					        <html:text name="emRuleDetailForm" size="3" maxlength="3" property="numItems" onkeypress="return checkNumberOnly(event)" />	
				                <html:checkbox name="emRuleDetailForm" property="includeSubCategory" />
					</logic:equal>
					<logic:notEqual name="emRuleDetailForm" property="ruleActionType" value="2" >
						<html:text name="emRuleDetailForm" size="3" maxlength="3" property="numItems" disabled="true" onkeypress="return checkNumberOnly(event)" />	
						<html:checkbox name="emRuleDetailForm" property="includeSubCategory" disabled="true" />
					</logic:notEqual>
					<bean:message bundle="em" key="emarketing.ruleset.text.includeSubCategories" />
					</td>
				</tr>

			</table>

			<div class="pageButtonWrap" align="right">
				<input	type="button" name="resetButton" class="inputButton"
						value="<bean:message bundle="em" key="button.reset"/>"
						onClick="doAction('/em/ruleset/ruleEdit.do', this.form);"> 
				&nbsp;&nbsp;
				<input type="button" name="cancelButton" class="inputButton"
						value="<bean:message bundle="em" key="button.cancel"/>"
						onClick="doCancel(this.form);" /> 
				<input	type="button" name="saveButton" class="inputButton"
						value="<bean:message bundle="em" key="button.save"/>" 
						onClick="if(validateForm(this.form)) doAction('/em/ruleset/ruleSave.do', this.form);" />
		      						
			</div>
			<br>
	</html:form>
	</td>
</tr>
</table>
